package main

import (
	"fmt"
	"github.com/aliyun/aliyun-oss-go-sdk/oss"
	"os"
)

// https://oss.console.aliyun.com/bucket/oss-cn-shanghai/chauncy/overview
var (
	endpint    = "oss-cn-shanghai.aliyuncs.com"
	acessKey   = "LTAI5t9KXrGgbvqcpdN1myk5"
	secretKey  = ""
	bucketName = "chauncy"
	uploadFile = "./go.mod"
)

func main() {
	if err := upload(uploadFile); err != nil {
		fmt.Printf("upload file error, %s\n", err)
		os.Exit(1)
	}
}

func upload(filePath string) error {
	client, err := oss.New(endpint, acessKey, secretKey)
	if err != nil {
		return err
	}

	bucket, err := client.Bucket(bucketName)
	if err != nil {
		return err
	}
	err = bucket.PutObjectFromFile("go.mod", filePath)
	if err != nil {
		return err
	}

	return nil
}
